Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Magik (programming language)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Magik_(programming_language)"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Magik_programming_language rootpage-Magik_programming_language skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Magik (programming language)</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */


.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}


/* end https://en.wikipedia.org/ */
</style>
<p><b>Magik</b> is an <a href="Object-oriented_programming" title="Object-oriented programming">object-oriented programming</a> language that supports <a href="Multiple_inheritance" title="Multiple inheritance">multiple inheritance</a> and <a href="Polymorphism_(computer_science)" title="Polymorphism (computer science)">polymorphism</a>, and it is <a href="Dynamic_typing" class="mw-redirect" title="Dynamic typing">dynamically typed</a>. It was designed and implemented in 1989 by Arthur Chance of <a href="Smallworld" title="Smallworld">Smallworld Systems Ltd.</a> as part of Smallworld Geographical Information System (GIS). Following Smallworld's acquisition in 2000, Magik is now provided by <a href="GE_Energy" class="mw-redirect" title="GE Energy">GE Energy</a>, still as part of its Smallworld technology platform.
</p><p>Magik (Inspirational Magik) was originally introduced in 1990 and has been improved and updated over the years. Its current version is 5.2.
</p><p>In July 2012, Magik developers announced that they were in the process of porting Magik language on the <a href="Java_virtual_machine" title="Java virtual machine">Java virtual machine</a>. The successful porting was confirmed by <a href="Oracle_Corporation" title="Oracle Corporation">Oracle Corporation</a> in November of the same year.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup>
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Similarities_with_Smalltalk">Similarities with Smalltalk</h2></div>
<p>Magik itself shares some similarities with <a href="Smalltalk" title="Smalltalk">Smalltalk</a> in terms of its language features and its architecture: the Magik language is compiled into <a href="Byte-code" class="mw-redirect" title="Byte-code">byte codes</a> interpreted by the Magik <a href="Virtual_machine" title="Virtual machine">virtual machine</a>. The Magik virtual machine is available on several platforms including <a href="Microsoft_Windows" title="Microsoft Windows">Microsoft Windows</a>, various flavours of <a href="Unix" title="Unix">Unix</a> and <a href="Linux" title="Linux">Linux</a>.
</p><p>Magik is console based and code can be modified on the fly even when an application is running. The console can also be used to execute Magik code and to see the results.
</p><p>Compiled code is stored in a single file called an image file. Each image file holds the compiled byte-codes and the state of the session (for example variable values) when the image was last saved.
</p>
<div class="mw-heading mw-heading2"><h2 id="Language_features">Language features</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Comments">Comments</h3></div>
<p>Magik uses the <code>#</code> token to mark sections of code as comments:
</p>
<pre> # This is a comment.
</pre>
<div class="mw-heading mw-heading3"><h3 id="Assignments">Assignments</h3></div>
<p>Magik uses the <code>&lt;&lt;</code> operator to make <a href="Assignment_(computer_science)" title="Assignment (computer science)">assignments</a>:
</p>
<pre> a &lt;&lt; 1.234
b &lt;&lt; b + a
c &lt;&lt; "foo" + "bar" # Concat strings
</pre>
<p>For clarity, this notation is read as "a becomes 1.234" or "b becomes b plus a". This terminology separates assignment from <a href="Comparison_(computer_programming)" class="mw-redirect" title="Comparison (computer programming)">comparison</a>.
</p><p>Magik also supports a compressed variation of this operator that works in a similar way to those found in <a href="C_(programming_language)" title="C (programming language)">C</a>:
</p>
<pre> b +&lt;&lt; a # Equivalent to b &lt;&lt; b + a
</pre>
<p>To print a variable you can use the following command
</p>
<pre> a &lt;&lt; "hello"
write(a)
</pre>
<div class="mw-heading mw-heading3"><h3 id="Symbols">Symbols</h3></div>
<p>As well as conventional data types such as integers, floats and strings Magik also implements symbols. Symbols are a special token data type that are used extensively throughout Magik to uniquely identify objects. They are represented by a colon followed by a string of characters. Symbols can be escaped using the <a href="Vertical_bar" title="Vertical bar">vertical bar</a> character. For example:
</p>
<pre> a &lt;&lt; :hello # whenever :hello is encountered, it is the same instance
b &lt;&lt;&nbsp;:|hello world|
</pre>
<div class="mw-heading mw-heading3"><h3 id="Dynamic_typing">Dynamic typing</h3></div>
<p>Magik variables are not typed as they are in say <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a> and can reference different objects at runtime. Everything in Magik is an object (there is no distinction between objects and primitive types such as integers):
</p>
<pre> a &lt;&lt; 1.2 # a floating point number is assigned to variable 'a'
a &lt;&lt; "1.2" # later, a string is assigned to variable 'a'
</pre>
<dl><dt>Objects</dt></dl>
<p>Objects are implemented in Magik using exemplars. Exemplars have similarities to classes in other programming languages such as <a href="Java_(programming_language)" title="Java (programming language)">Java</a>, but with important differences. Magik supports multiple inheritance, and <a href="Mixin" title="Mixin">mixins</a> (which implement functionality with no data). New instances are made by cloning an existing instance (which will typically be the exemplar but does not have to be).
</p><p>New exemplars are created using the statement <code>def_slotted_exemplar()</code>, for example:
</p>
<pre> def_slotted_exemplar(:my_object,
{
{:slot_a, 34},
{:slot_b, "hello"}
}, {:parent_object_a, :parent_object_b})
</pre>
<p>This code fragment will define a new exemplar called <code>my_object</code> that has two slots (or fields) called <code>slot_a</code> (pre-initialised to 34) and <code>slot_b</code> (pre-initialised to "hello") that inherits from two existing exemplars called <code>parent_object_a</code> and <code>parent_object_b</code>.
</p>
<div class="mw-heading mw-heading3"><h3 id="Comparison">Comparison</h3></div>
<p>Magik implements all usual logical operators (<code>=</code>, <code>&lt;</code>, <code>&lt;=</code>, <code>&gt;</code>, <code>&gt;=</code>, <code>~=/&lt;&gt;</code>) for comparison, as well as a few unusual ones. The <code>_is</code> and <code>_isnt</code> operators are used for comparing specific instances of objects, or object references rather than values.
</p><p>For example:
</p>
<pre> a &lt;&lt; "hello"
b &lt;&lt; "hello"

a = b # returns True (_true) because the values of a and b are equal
a _is b # returns False (_false) because a is not the same instance as b

a &lt;&lt; "hello"
b &lt;&lt; a
a = b # returns True (_true) because the values of a and b are equal
a _is b # returns True (_true) because b was assigned the specific instance of the same object as a, rather than the value of a.
</pre>
<div class="mw-heading mw-heading3"><h3 id="Methods">Methods</h3></div>
<p>Methods are defined on exemplars using the statements <code>_method</code> and <code>_endmethod</code>:
</p>
<pre> _method my_object.my_method(a, b)
_return a + b
_endmethod
</pre>
<p>It is convention to supply two methods <code>new()</code> (to create a new instance) and <code>init()</code> (to initialise an instance).
</p>
<pre> # New method
_method person.new(name, age)
_return _clone.init(name, age)
_endmethod

# Initialise method.
_private _method person.init(name, age)
# Call the parent implementation.
_super.init(name, age)
# Initialise the slots.
.name &lt;&lt; name
.age &lt;&lt; age
_return _self
_endmethod
</pre>
<p>The <code>_clone</code> creates a physical copy of the <code>person</code> object. The <code>_super</code> statement allows objects to invoke an implementation of a method on the parent exemplar. Objects can reference themselves using the <code>_self</code> statement. An object's slots are accessed and assigned using a dot notation.
</p><p>Methods that are not part of the public interface of the object can be marked private using the <code>_private</code> statement. Private methods can only be called by <code>_self</code>, <code>_super</code> and <code>_clone</code>.
</p><p>Optional arguments can be declared using the <code>_optional</code> statement. Optional arguments that are not passed are assigned by Magik to the special object <code>_unset</code> (the equivalent of null). The <code>_gather</code> statement can be used to declare a list of optional arguments.
</p>
<pre> _method my_object.my_method(_gather values)
_endmethod
</pre>
<div class="mw-heading mw-heading3"><h3 id="Iteration">Iteration</h3></div>
<p>In Magik the <code>_while</code>, <code>_for</code>, <code>_over</code>, <code>_loop</code> and <code>_endloop</code> statements allow iteration.
</p>
<pre>_block
_local s &lt;&lt; 0
_local i &lt;&lt; 0
_while i &lt;= 100
_loop
s +&lt;&lt; i
i +&lt;&lt; 1
_endloop
&gt;&gt; s
_endblock
</pre>
<p>Here, the _while is combined with _loop and _endloop.
</p>
<pre> _method my_object.my_method(_gather values)
total &lt;&lt; 0.0
_for a _over values.elements()
_loop
total +&lt;&lt; a
_endloop
_return total
_endmethod

m &lt;&lt; my_object.new()
x &lt;&lt; m.my_method(1.0, 2, 3.0, 4) # x = 10.0
</pre>
<p>Here values.elements() is an iterator which helps to iterate the values.
</p><p>In Magik <a href="Generator_(computer_science)" class="mw-redirect" title="Generator (computer science)">generator</a> methods are called iterator methods. New iterator methods can be defined using the <code>_iter</code> and <code>_loopbody</code> statements:
</p>
<pre> _iter _method my_object.even_elements()
_for a _over _self.elements()
_loop
_if a.even? _is _true
_then
_loopbody(a)
_endif
_endloop
_endmethod
</pre>
<div class="mw-heading mw-heading3"><h3 id="Procedures">Procedures</h3></div>
<p>Magik also supports functions called procedures. Procedures are also objects and are declared using the <code>_proc</code> and <code>_endproc</code> statements. Procedures are assigned to variables which may then be invoked:
</p>
<pre> my_procedure &lt;&lt; _proc @my_procedure(a, b, c)
_return a + b + c
_endproc

x &lt;&lt; my_procedure(1, 2, 3) # x = 6
</pre>
<div class="mw-heading mw-heading3"><h3 id="Regular_expression">Regular expression</h3></div>
<p>Magik supports // regular expression syntax:
</p>
<pre>_if /Hello\,\s(\w)+!/.matches?("Hello, Magik!") _then
write("Got a match!")
_endif
</pre>
<p>and to capture groups in Regex:
</p>
<pre>/sw([0-9]+)-([0-9]+).*/.replace_all("sw65456-324sss", "$1") # "65456"
/sw([0-9]+)-([0-9]+).*/.replace_all("sw65456-324sss", "$2") # "324"
</pre>
<div class="mw-heading mw-heading3"><h3 id="HTTP_library">HTTP library</h3></div>
<p>Magik supports making HTTP or HTTPS requests via http library, see below examples:
</p>
<pre>magikhttp &lt;&lt; http.new()
magikhttp.url("https://www.google.com").get()
magikhttp.url("https://www.google.com").post({"User-agent", "Bot"}, "some data")
</pre>
<div class="mw-heading mw-heading3"><h3 id="Language_quirks">Language quirks</h3></div>
<p>Because Magik was originally developed in England, methods in the core smallworld libraries are spelled using <a href="British_English" title="British English">British English</a>. For example:
</p>
<pre> Use "initialise", not "initialize".
</pre>
<div class="mw-heading mw-heading3"><h3 id="Collections">Collections</h3></div>
<p>Like other programming language Magik too has collections. They include the following:
</p>
<ul><li>Simple Vector</li>
<li>Rope - a <a href="Dynamic_array" title="Dynamic array">dynamic array</a></li>
<li><a href="Hash_Table" class="mw-redirect" title="Hash Table">Hash Table</a></li>
<li>Property List</li>
<li>Equality set</li>
<li>Bags</li></ul>
<div class="mw-heading mw-heading2"><h2 id="Hello_World_example">Hello World example</h2></div>
<p>The following is an example of the <a href="Hello_world_program" class="mw-redirect" title="Hello world program">Hello world program</a> written in Magik:
</p>
<pre> write("Hello World!")
</pre>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFJim_Connors2012" class="citation web cs1">Jim Connors (2012-11-05). <a rel="nofollow" class="external text" href="https://blogs.oracle.com/jtc/entry/sprinkle_some_magik_on_that">"Sprinkle Some Magik on that Java Virtual Machine"</a><span class="reference-accessdate">. Retrieved <span class="nowrap">2012-11-06</span></span>. <q><i>With this new capability GE Energy has succeeded in hosting their Magik environment on top of the Java Virtual Machine</i></q></cite></span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="http://www.ge-energy.com/products_and_services/products/geospatial_systems_and_mobile_workforce/index.jsp">Smallworld Product Suite Technology</a></li>
<li><a rel="nofollow" class="external text" href="http://www.mdt.net/">MDT - Magik Development Tools</a> IDE for GE Smallworld GIS developers</li>
<li><a rel="nofollow" class="external text" href="http://sourceforge.net/projects/magikcmpnts">Open Source (SourceForge)</a></li>
<li><a rel="nofollow" class="external text" href="http://lambda-the-ultimate.org/classic/message5839.html#5886">Language forum post on Magik</a></li>
<li><a rel="nofollow" class="external text" href="https://archive.today/20061020015202/http://cfis.savagexi.com/pages/technical_paper_5">Technical Paper No. 5 - An Overview of Smallworld Magik</a></li>
<li><a rel="nofollow" class="external text" href="http://www.magikemacs.com/page/6/">GE Smallworld, Emacs Extensions for Magik developers</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160425011048/http://www.magikemacs.com/page/6/">Archived</a> 2016-04-25 at the <a href="Wayback_Machine" title="Wayback Machine">Wayback Machine</a></li>
<li><a rel="nofollow" class="external text" href="https://marketplace.visualstudio.com/items?itemName=siamz.smallworld-magik">Visual Studio Code extension for Smallworld Magik programming language.</a></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-29" href="https://en.wikipedia.org/wiki/?title=Magik_(programming_language)&amp;oldid=1303244652">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>